unit UZLibFunc;

interface
uses Classes, SysUtils,
  ZlibEx;

function Compress(InputFileName, OutputFileName: String): Boolean;
function Decompress(InputFileName, OutputFileName: String): Boolean;

implementation

function Compress(InputFileName, OutputFileName: String): Boolean;
var
  InputStream, OutputStream: TFileStream;
  CompressionStream: TZCompressionStream;
begin
  //compress
  
  Result := True;
  try
    InputStream := TFileStream.Create(InputFileName, fmOpenRead);
    OutputStream := TFileStream.Create(OutputFileName, fmCreate);
    CompressionStream := TZCompressionStream.Create(OutputStream, zcFastest);
    CompressionStream.CopyFrom(InputStream, InputStream.Size);
    CompressionStream.Free;
    OutputStream.Free;
    InputStream.Free;
  except
    Result := False;
  end;
end;


function Decompress(InputFileName, OutputFileName: String): Boolean;
var
  InputStream, OutputStream: TFileStream;
  DeCompressionStream: TZDecompressionStream;
begin
  // decompress

  Result := True;
  try
    InputStream := TFileStream.Create(InputFileName, fmOpenRead);
    OutputStream := TFileStream.Create(OutputFileName, fmCreate);
    DecompressionStream := TZDecompressionStream.Create(InputStream);
    OutputStream.CopyFrom(DecompressionStream, 0);
    DecompressionStream.Free;
    OutputStream.Free;
    InputStream.Free;
  except
    Result := False;
  end;
end;

end.
